package com.ruoyi.system.controller;

import java.math.BigDecimal;
import java.util.List;
import java.io.IOException;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

import com.ruoyi.common.core.exception.ServiceException;
import com.ruoyi.common.security.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.domain.IaeInternalTransfer;
import com.ruoyi.system.service.IIaeInternalTransferService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 内部转账记录Controller
 * 
 * @author ruoyi
 * @date 2025-02-27
 */
@RestController
@RequestMapping("/transfer")
public class IaeInternalTransferController extends BaseController
{
    @Autowired
    private IIaeInternalTransferService iaeInternalTransferService;

    /**
     * 查询内部转账记录列表
     */
    @RequiresPermissions("system:transfer:list")
    @GetMapping("/list")
    public TableDataInfo list(IaeInternalTransfer iaeInternalTransfer)
    {
        startPage();
        List<IaeInternalTransfer> list = iaeInternalTransferService.selectIaeInternalTransferList(iaeInternalTransfer);
        return getDataTable(list);
    }

    /**
     * 导入内部转账数据
     */
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception {
        ExcelUtil<IaeInternalTransfer> util = new ExcelUtil<>(IaeInternalTransfer.class);
        List<IaeInternalTransfer> transferList = util.importExcel(file.getInputStream());
        String operName = SecurityUtils.getUsername();
        String message = iaeInternalTransferService.importTransfer(transferList, updateSupport, operName);
        return success(message);

    }
    /**
     * 下载导入模板
     */
    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response) throws Exception {
        ExcelUtil<IaeInternalTransfer> util = new ExcelUtil<IaeInternalTransfer>(IaeInternalTransfer.class);
        util.importTemplateExcel(response, "内部转账数据");
    }

    /**
     * 导出内部转账记录列表
     */
    @RequiresPermissions("system:transfer:export")
    @Log(title = "内部转账记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, IaeInternalTransfer iaeInternalTransfer)
    {
        List<IaeInternalTransfer> list = iaeInternalTransferService.selectIaeInternalTransferList(iaeInternalTransfer);
        ExcelUtil<IaeInternalTransfer> util = new ExcelUtil<IaeInternalTransfer>(IaeInternalTransfer.class);
        util.exportExcel(response, list, "内部转账记录数据");
    }

    /**
     * 获取内部转账记录详细信息
     */
    @RequiresPermissions("system:transfer:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(iaeInternalTransferService.selectIaeInternalTransferById(id));
    }

    /**
     * 新增内部转账记录
     */
    @RequiresPermissions("system:transfer:add")
    @Log(title = "内部转账记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody IaeInternalTransfer iaeInternalTransfer)
    {
        return toAjax(iaeInternalTransferService.insertIaeInternalTransfer(iaeInternalTransfer));
    }

    /**
     * 修改内部转账记录
     */
    @RequiresPermissions("system:transfer:edit")
    @Log(title = "内部转账记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody IaeInternalTransfer iaeInternalTransfer)
    {
        return toAjax(iaeInternalTransferService.updateIaeInternalTransfer(iaeInternalTransfer));
    }

    /**
     * 批量删除内部转账记录
     */
    @RequiresPermissions("system:transfer:remove")
    @Log(title = "内部转账记录", businessType = BusinessType.DELETE)
	@PostMapping("/ids")
    public AjaxResult removes(@Validated @RequestBody Map<String, Long[]> map)
    {
        Long[] ids = map.get("ids");
        return toAjax(iaeInternalTransferService.deleteIaeInternalTransferByIds(ids));
    }
    /**
     * 删除内部转账记录
     */
    @RequiresPermissions("system:transfer:remove")
    @Log(title = "内部转账记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{id}")
    public AjaxResult remove(@Validated @PathVariable Long id)
    {
        return toAjax(iaeInternalTransferService.deleteIaeInternalTransferById(id));
    }


}
